package edu.gduf.controller;

import edu.gduf.domain.ResultInfo;
import edu.gduf.domain.User;
import edu.gduf.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;


/**
 * @author 谢佳豪
 * @data 2020/9/11 - 21:40
 * @target user表的控制类
 */
@RestController
@RequestMapping("/user")
public class UserController {

    private UserServiceImpl userService;

    @Autowired
    public void setUserService(UserServiceImpl userService) {
        this.userService = userService;
    }

    @RequestMapping("/pageQuery")
    public ResultInfo pageQuery(Integer pageIndex) {
        return userService.pageQuery(pageIndex - 1);
    }

    @RequestMapping("/login")
    public ResultInfo login(String username, String password, HttpSession httpSession) {
        return userService.login(username, password, httpSession);
    }

    @RequestMapping("/addUser")
    public ResultInfo addUser(User user, HttpSession httpSession) {
        return userService.addUser(user, httpSession);
    }

    @RequestMapping("/byIdDeleteUser")
    public ResultInfo byIdDeleteUser(Integer id, HttpSession httpSession) {
        return userService.byIdDeleteUser(id, httpSession);
    }

    @RequestMapping("/updateUser")
    public ResultInfo updateUser(User user, HttpSession httpSession) {
        return userService.updateUser(user, httpSession);
    }

    @RequestMapping("logout")
    public ResultInfo logoutUser(HttpSession session){
        session.invalidate();
        return ResultInfo.successInfo("成功登出,祝您工作愉快");
    }
}
